import request from '@/utils/request'

/**
 * 佣金管理
 * 包含佣金管理页面的 初始化/查询/分页/dialog
 * @export {init,search,page}
 */
export function init(id) {
  return request({
    url: '/agent/bkge/list',
    method: 'GET',
    params: { id }
  })
}

/**
 * 佣金管理搜索
 * @param {Number} id 代理商id
 * @param {Array} date 搜索参数
 */
export function search(id, date) {
  return request({
    url: '/agent/bkge/list',
    method: 'GET',
    params: { id, agent_num: date.agent_name, start: date.time ? date.time[0] : '', stop: date.time ? date.time[1] : '' }
  })
}

/**
 * 模态框数据获取
 * @param {Number} id 代理商id
 */
export function dialog(agent_num, bkge_id) {
  return request({
    url: '/agent/bkge/record/lists',
    method: 'GET',
    params: { agent_num, bkge_id }
  })
}

/**
 * 模态框数据分页
 * @param {Number} id 代理商id
 */
export function dialogPage(page, date) {
  return request({
    url: '/agent/bkge/record/lists',
    method: 'GET',
    params: { agent_num: date.agent_num, bkge_id: date.id, page }
  })
}

/**
 * 佣金管理分页
 * @param {Number} page 页码
 * @param {Object} date 参数
 */
export function page(page, date) {
  return request({
    url: '/agent/bkge/list',
    method: 'GET',
    params: { page, agent_num: date.agent_name, start: date.time ? date.time[0] : '', stop: date.time ? date.time[1] : '' }
  })
}

/**
 * 佣金详情获取
 * @param {Number} agent_num 代理商id
 * @param {Number} date 时间
 */
export function bkgeDetail(agent_num, date) {
  return request({
    url: 'agent/bkge/detail',
    method: 'GET',
    params: { agent_num, date }
  })
}

/**
 * 本级提现管理
 * 初始化页面数据
 * @export
 * @returns JSON
 */
export function withdrawInit() {
  return request({
    url: 'agent/finance/get_reflect_merchant',
    method: 'GET'
  })
}

/**
 * 本级提现分页
 * @export
 * @param {any} date 查询参数
 * @param {any} page 当前页码
 * @returns JSON
 */
export function withdrawPage(date, page) {
  return request({
    url: 'agent/finance/get_reflect_merchant',
    method: 'GET',
    params: { option: date.option, start: date.start, stop: date.stop, page }
  })
}

/**
 * 本级提现查询
 * @param {Array} date 查询参数
 */
export function withdrawSearch(date) {
  return request({
    url: 'agent/finance/get_reflect_merchant',
    method: 'GET',
    params: { option: date.option, start: date.start, stop: date.stop }
  })
}

/**
 * 提现弹框数据获取
 */
export function DialogList() {
  return request({
    url: 'agent/finance/get_postal_bank',
    method: 'GET'
  })
}

/**
 * 提现弹框确认提现
 * @param {Number} money 提现金额
 */
export function subRate(money) {
  const data = { money }
  return request({
    url: 'agent/finance/create_postal',
    method: 'POST',
    data
  })
}

/**
 * 下级提现初始化
 * @param {Number} id 代理商id
 */
export function nextInit(id) {
  return request({
    url: 'agent/finance/get_down_reflect_merchant',
    method: 'GET',
    params: { id }
  })
}

/**
 * 下级提现查看详情
 * @param {Number} cash_num
 */
export function nextDialog(cash_num) {
  return request({
    url: 'agent/finance/get_finance_cash_detail',
    method: 'GET',
    params: { cash_num }
  })
}

/**
 * 下级提现分页
 * @export
 * @param {any} id 代理商id
 * @param {any} date 查询参数
 * @param {any} page 当前页码
 * @returns JSON
 */
export function nextPage(id, page, date) {
  return request({
    url: 'agent/finance/get_down_reflect_merchant',
    method: 'GET',
    params: { id, option: date.option, start: date.time ? date.time[0] : '', stop: date.time ? date.time[1] : '', agent_name: date.sr, page }
  })
}

/**
 * 下级提现查询
 * @param {Number} id 代理商id
 * @param {Array} date 查询参数
 */
export function nextSearch(id, date) {
  return request({
    url: 'agent/finance/get_down_reflect_merchant',
    method: 'GET',
    params: { id, option: date.option, start: date.time ? date.time[0] : '', stop: date.time ? date.time[1] : '', agent_name: date.sr }
  })
}

/**
 * 下级提现确认打款
 * @param {Array} num 打款数组id
 */
export function success(num) {
  const data = { num }
  return request({
    url: 'agent/finance/update_success',
    method: 'POST',
    data
  })
}

/**
 * 下级提现拒绝打款
 * @param {Array} num 打款数组id
 */
export function faild(num) {
  const data = { num }
  return request({
    url: 'agent/finance/update_fail',
    method: 'POST',
    data
  })
}

/**
 * 平安见证宝初始化
 */
export function handleWitnessInit() {
  return request({
    url: '/safety',
    method: 'GET'
  })
}

/**
 * 平安见证宝更新状态
 * @param {Number} order_status 流水号
 * @param {Number} current 当前页
 */
export function updatedInit(withdraw_no) {
  return request({
    url: '/order_status',
    method: 'GET',
    params: { withdraw_no }
  })
}

/**
 * 平安见证宝提现
 * @param {Number} tran_amount 提现金额
 */
export function pnReflectInit(tran_amount) {
  return request({
    url: '/agentreflect',
    method: 'GET',
    params: { tran_amount }
  })
}

/**
 * 平安见证宝提现分页
 * @param {Number} page 页码
 */
export function pnReflectPage(page) {
  return request({
    url: '/safety',
    method: 'GET',
    params: { page }
  })
}

/**
 * 平安对账单下载
 * @param {Object} date 查询参数
 */
export function paDownload(date) {
  const data = {
    bill_date: date.time,
    pay_platform: date.pay_id,
    file_type: date.type_id
  }
  return request({
    url: '/finance_download_bill',
    method: 'POST',
    data
  })
}
